package StreanmLearn.Gather;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;

public class 初识collect {
    public static void main(String[] args) {
        ArrayList<String> list=new ArrayList<>();

        Collections.addAll(list,"妲己-女-26","张无忌-男-23","李四-男-32","张强-男-64","张三丰-男-23","王五-男-65","克莱普-妖-21","谢广坤-男-17");

        //收集list集合当中
        //需求:
        //收集性别为男的
        List<String> newlist=list.stream()
                .filter(s->"男".equals(s.split("-")[1]))
                .collect(Collectors.toList());
        //打印收集到的数据
        //System.out.println(newlist);

        //收集Set集合当中
        //需求:
        //收集性别为男的
        Set<String> newSet=list.stream()
                .filter(s->"男".equals(s.split("-")[1]))
                .collect(Collectors.toSet());
        //打印收集到的数据
        //System.out.println(newSet);

        /*
        list与Set的区别:
        list不可以去重，Set可以去重
         */
        list.stream()
                .filter(s ->"男".equals(s.split("-")[1]))
                /*
                toMap:参数一表示
                 */


                .collect(Collectors.toMap(new Function<String, String>() {
                    @Override
                    public String apply(String s) {
                        return null;
                    }
                    },
                        new Function<String, String>() {
                    @Override
                    public String apply(String s) {
                        return null;
                    }
                }));




    }
}
